package com.aischool.webapp.teacher;

import java.util.Date;

import com.aischool.params.AiCourseParams;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiCourseClassService;
import com.aischool.service.AiCoursePlanService;
import com.aischool.service.AiCourseService;
import com.aischool.utils.AppUtil;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;

@RouteMapping(url = "/front/teacher/course")
public class AiCourseController extends BaseTeacherController {

	@Inject
	AiCoursePlanService aiCoursePlanService;
	@Inject
	AiCourseClassService aiCourseClassService;
	@Inject
	AiCourseService aiCourseService;

	public void getCoursePlan() {
		// 结果类
		JsonResult jr = new JsonResult();

		int login_class_id = this.getAttrForInt("login_class_id");	
		Date start_date = getDate("startdate");
		Date end_date = getDate("enddate");
		
		Object obj = aiCoursePlanService.getCoursePlan(login_class_id, start_date, end_date);
		
		jr.setDicKV("list_course", obj);
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	

	public void getPage() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		int org_id = this.getAttrForInt("login_org_id");
		
		int article_catid = getInt("article_catid", 0);
		
		// 参数类
		AiCourseParams params = new AiCourseParams();
		
		params.setPageNo(getParaToInt("pageNo", 1));
		params.setPageSize(getParaToInt("pageSize", AppUtil.Default_PageSize));

		params.setState(1);
		params.setOrgId(org_id);
		
		params.setArticle_Catid(article_catid);

		// 获取分页
		Object pageData = aiCourseService.getPage(params);
		
		jr.setDicKV("pageData", pageData);
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	
	public void detaile() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		int course_id = getParaToInt("id",0);
		if (course_id > 0) {
			Object obj = aiCourseService.getOne(course_id);
			if (obj != null) { 
				jr.setDicKV("course_rd", obj); 
			}
			obj = aiCourseClassService.getClass(course_id);
			if (obj != null) { 
				jr.setDicKV("list_courseclass", obj); 
			}
		}
		
		renderJson(jr.Dic);
	}
}
